package araxy.blog.configuration;

import araxy.blog.utils.TokenUtil;
import com.nimbusds.jose.*;
import com.nimbusds.jose.crypto.MACSigner;
import com.nimbusds.jose.crypto.MACVerifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JwtConfiguration {
    @Bean
    public JWSHeader defaultJWSHeader() {
        return new JWSHeader.Builder(JWSAlgorithm.HS256).type(JOSEObjectType.JWT).build();
    }

    @Bean
    public JWSVerifier defaultJWSVerifier () throws JOSEException {
        return new MACVerifier(TokenUtil.getSecret());
    }

    @Bean
    public JWSSigner defaultJWSSigner () throws KeyLengthException {
        return new MACSigner(TokenUtil.getSecret());
    }
}
